<template>
  <div class="container">
    <Nav></Nav>
    <!-- 举报页面 -->
    <div class="main-container">
      <div class="report-wrap">
        <h1>举报</h1>
        <div class="divider"></div>
        <!-- 表单内容 -->
        <form action="">
          <h2>举报问题</h2>
          <div class="radio-group">
            <!-- 单选框 -->
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="内容质量太差"
                  @click="reveal3"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">内容质量太差</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="低俗色情"
                  @click="reveal3"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">低俗色情</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="涉及违法"
                  @click="reveal3"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">涉及违法</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="恶意营销"
                  @click="reveal3"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">恶意营销</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="内容抄袭"
                  @click="reveal"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">内容抄袭</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="其他原因"
                  @click="reveal3"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">其他原因</span>
            </label>
            <label>
              <span>
                <input
                  type="radio"
                  name="report"
                  class="byte-radio"
                  value="侵犯名誉/隐私/著作/肖像权等"
                  @click="reveal1"
                  v-model="sub.gender"
                />
              </span>
              <span class="byte-p">侵犯名誉/隐私/著作/肖像权等</span>
            </label>
          </div>
          <!-- 隐藏框  -->
          <div class="inline-form">
            <div class="copy" v-if="show1">
              <h2>原创链接</h2>
              <label for="">
                <div class="byte-form-item">
                  <span class="byte-form-item_label">原创链接</span>
                  <span
                    ><input
                      type="text"
                      class="byte-input_input"
                      @change="description1"
                      v-model="sub.link"
                  /></span>
                </div>
              </label>
            </div>
            <div class="violate" v-if="show2">
              <h2>权利人资料</h2>
              <label for="">
                <div class="byte-form-item">
                  <span class="byte-form-item_label">姓名</span>
                  <span
                    ><input type="text" class="byte-input_input" v-model="sub.name"
                  /></span>
                </div>
              </label>
              <label for="">
                <div class="byte-form-item">
                  <span class="byte-form-item_label">手机号</span>
                  <span
                    ><input
                      type="text"
                      class="byte-input_input"
                      v-model="sub.phone"
                  /></span>
                </div>
              </label>
            </div>
          </div>
          <!-- 选择文件 -->
          <div class="byte-form-items">
            <div class="byte-form-content">
              <h2>证明材料</h2>
              <div class="img-uploader">
                <input type="file" class="input-file" @change="onChange"/>
              </div>
            </div>
          </div>
          <!-- 文本输入框 -->
          <div class="byte-form-content">
            <h2>举报描述</h2>
            <div class="byte-input">
              <textarea
                maxlength="200"
                name=""
                id=""
                cols="30"
                rows="4"
                placeholder="您可以在此处填写举报说明，最多不超过 200 个字"
                class="byte-input__textarea"
                v-model="sub.description"
                @blur="description1"
                style="margin-top: 0px; margin-bottom: 0px; height: 76px"
              ></textarea>
            </div>
          </div>
        </form>
        <div class="button-wrap">
          <button class="submit" @click="submit">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Nav from "../../components/nav.vue";
export default {
  data() {
    return {
      // 显示还是隐藏
      show1: false,
      show2: false,
      arr:'',

      // 提交的单个对象
      sub: {
        gender: "内容质量太差",
        // 原创链接
        link: "",
        // 权利人资料
        name: "",
        phone: "",
        // 提交文件的内容
        file: "",
        // 举报描述内容
        description: "",
      },
      // 最后提交的json
      info: [],
    };
  },
  methods: {
    reveal() {
      this.show1 = true;
      this.show2 = false;
    },
    reveal1() {
      this.show2 = true;
      this.show1 = false;
    },
    reveal3() {
      this.show2 = false;
      this.show1 = false;
    },
    description1() {
      console.log(this.sub.description);
      console.log(this.sub.link);
    },
    // 传入文件的函数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    onChange(event) {
      this.arr1 =  (event.target.files[0].name).split(".")[1]
      if(this.arr1 == "jpg" || this.arr1 =="png"){
      this.sub.file = event.target.files[0].name;
      console.log(this.sub.file);
      }else {
        alert("请传入正确的图片格式")
      }

    },
    // 点击提交按钮，传入数据
    submit() {
      this.info.push(this.sub)
      console.log(this.info);
      alert("恭喜你啊，卧龙兄，举报成功！")
      this.$router.push({path:"../article/:id"})
    },
  },
  components: {
    Nav,
  },
};
</script>
<style>
.main-container {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 960px;
}

.report-wrap {
  padding: 30px 50px;
  background: #fff;
  border-radius: 3px;
  width: 700px;
  box-sizing: border-box;
  margin-top: 40px;
}
/* 标题 */
.report-wrap h1 {
  font-weight: 600;
  font-size: 26px;
  line-height: 18px;
  color: #333;
}
.report-wrap .divider {
  height: 2px;
  width: 100%;
  background-color: #eaeaea;
  margin: 38px 0 29px;
}
/* 表单 */
form {
  display: block;
}
.radio-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
label {
  cursor: pointer;
  display: inline-block;
  position: relative;
  white-space: nowrap;
  line-height: 25px;
  margin-right: 35px;
  color: #282f38;
  vertical-align: top;
  font-size: 14px;
}
.report-wrap h2 {
  font-weight: 600;
  font-size: 17px;
  line-height: 24px;
  margin: 14px 0 20px;
}
/* 单选框左边的框 */
.byte-radio {
  width: 16px;
  height: 16px;
  border: 1px solid #bfcbd9;
  border-radius: 50%;
  background-color: #fff;
  cursor: pointer;
  box-sizing: border-box;
  position: relative;
  outline: none;
}
/* 单选框右边的字 */
.byte-p {
  margin-left: 16px;
}

.byte-form-items {
  margin-bottom: 28px;
}
/* 隐藏的内容 */
.inline-form label {
  width: 380px;
  margin-bottom: 28px;
}
.byte-form-item {
  display: flex;
  justify-content: space-between;
}
.byte-input_input {
  vertical-align: middle;
  height: 32px;
  font-size: 14px;
  line-height: 1.5;
  width: 286px;
  border: 1px #999 solid;
  padding: 0 10px;
}
.byte-form-item_label {
  float: left;
  text-align: right;
  vertical-align: middle;
  font-size: 14px;
  line-height: 32px;
  padding-right: 20px;
  color: #939aa3;
}
/* 提交文件部分 */
.img-uploader {
  cursor: pointer;
  display: flex;
  align-items: flex-start;
}
.input-file {
  appearance: initial;
  background-color: initial;
  cursor: default;
  align-items: baseline;
  color: inherit;
  text-overflow: ellipsis;
  white-space: pre;
  text-align: start !important;
  padding: initial;
  border: initial;
  overflow: hidden !important;
}
/* 最下面的文字输入框 */
.byte-input__textarea {
  border: 1px solid #e6e8eb;
  border-radius: 2px;
  position: relative;
  width: 100%;
  display: inline-block;
  color: #282f38;
  line-height: 1.5;
  background-color: #fff;
  transition: all 0.3s;
  box-sizing: border-box;
  outline: 0;
  height: 32px;
  font-size: 14px;
  height: auto;
  padding: 6px 10px;
  vertical-align: top;
  transition: all 0.3s, 0s;
  resize: vertical;
}

/* 提交按钮 */
.report-wrap .button-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 22px;
}
.submit {
  background: #007fff;
  border-radius: 3px;
  width: 166px;
  height: 44px;
  font-size: 15px;
  line-height: 18px;
  color: #fff;
  text-align: center;
  cursor: pointer;
}
</style>